package com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use;

import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.Request;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.UserRequest;

// 用户请求

 class UserHandler extends Handler {
    @Override
    public void handleRequest(Request request) {
        if (request instanceof UserRequest) {
            UserRequest userRequest = (UserRequest) request;
            if (userRequest.getUser() != null && userRequest.getUser().isAuthenticated()) {
                System.out.println("用户验证通过！");
            } else {
                System.out.println("用户验证失败！");
                return; // 验证失败，不再传递请求
            }
        }
        // 如果本处理者处理后请求未被结束，则继续传递
        if (successor != null) {
            successor.handleRequest(request);
        }
    }
}